package com.tanhua.manage.controller;


import com.tanhua.common.utils.NoAuthorization;
import com.tanhua.manage.service.VideoService;
import com.tanhua.manage.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("management/manage/videos")
public class VideoController {


    @Autowired
    private VideoService videoService;
    /**
     * 视频记录翻页
     * @param page
     * @param pagesize
     * @param sortProp   排序字段
     * @param sortOrder  ascending 升序 descending 降序
     * @param uid
     * @return
     */
    @GetMapping
    @NoAuthorization
    public ResponseEntity<PageResult> queryVideoList(@RequestParam(name = "page")Integer page,
                                                     @RequestParam(name = "pagesize")Integer pagesize,
                                                     @RequestParam(name = "sortProp")String sortProp,
                                                     @RequestParam(name = "sortOrder")String sortOrder,
                                                     @RequestParam(name = "uid")Long uid){
        try {
            if (page<=0){
                page=1;
            }

            PageResult pageResult = this.videoService.queryVideoListById(page, pagesize, uid, sortOrder, sortProp);

            if (null!=pageResult){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
